#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
  pid_t id  = fork();
  if(id == 0)
  {
    //子进程
    int cnt = 5;
    while(cnt)
    {
      printf("我是一个子进程，pid:%d, ppid:%d\n",getpid(),getppid());
      sleep(1);
      cnt--;
    }
    exit(0);//退出子进程
  }
  //父进程
  //1.子进程退出
  //2.子进程没有退出呢？？wait在干啥
  sleep(10);
  //pid_t rid = wait(NULL);
  pid_t rid = waitpid(id,NULL,0);
  if(rid > 0)
  {
    printf("wait success,rid: %d\n",rid);//rid
  }
  sleep(10);
  return 0;
}
